import { customRef } from 'vue';

// 自定义ref
export default function(value) {
    let timer = null;

    return customRef((track, trigger) => {
        return {
            get() {
                // track收集对应的依赖
                track();
                return value;
            },
            set(newValue) {
                // value = newValue;
                // trigger();
                // 防抖
                clearTimeout(timer);
                timer = setTimeout(() => {
                    value = newValue;
                    trigger();
                }, 1000)
            }
        }
    })
}